package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyGoodsMapper;
import com.laowang.project.system.domain.MyGoods;
import com.laowang.project.system.service.MyGoodsService;

/**
 * 商品Service业务层处理
 *
 * @author laowang
 * @date 2023-07-19
 */
@Service
public class MyGoodsServiceImpl implements MyGoodsService {
    @Autowired
    private MyGoodsMapper myGoodsMapper;

    /**
     * 查询商品
     *
     * @param id 商品ID
     * @return 商品
     */
    @Override
    public MyGoods selectMyGoodsById(Integer id) {
        return myGoodsMapper.selectMyGoodsById(id);
    }

    /**
     * 查询商品列表
     *
     * @param myGoods 商品
     * @return 商品
     */
    @Override
    public List<MyGoods> selectMyGoodsList(MyGoods myGoods) {
        return myGoodsMapper.selectMyGoodsList(myGoods);
    }

    /**
     * 新增商品
     *
     * @param myGoods 商品
     * @return 结果
     */
    @Override
    public int insertMyGoods(MyGoods myGoods) {
        Integer isCombo = myGoods.getIsCombo();
        if (isCombo == 2){
            Integer jifen = myGoods.getJifen();
            if (jifen == null) throw new CustomException("商品积分数值不能为空");
                Integer jinbi = myGoods.getJinbi();
            if (jinbi == null) throw new CustomException("商品金币数值不能为空");
        }
        return myGoodsMapper.insertMyGoods(myGoods);
    }

    /**
     * 修改商品
     *
     * @param myGoods 商品
     * @return 结果
     */
    @Override
    public int updateMyGoods(MyGoods myGoods) {
        return myGoodsMapper.updateMyGoods(myGoods);
    }

    /**
     * 批量删除商品
     *
     * @param ids 需要删除的商品ID
     * @return 结果
     */
    @Override
    public int deleteMyGoodsByIds(Integer[] ids) {
        return myGoodsMapper.deleteMyGoodsByIds(ids);
    }

    /**
     * 删除商品信息
     *
     * @param id 商品ID
     * @return 结果
     */
    @Override
    public int deleteMyGoodsById(Integer id) {
        return myGoodsMapper.deleteMyGoodsById(id);
    }

    @Override
    public List<MyGoods> selectMyGoodsListWeb(MyGoods myGoods) {
        return myGoodsMapper.selectMyGoodsListWeb(myGoods);
    }
}
